package Interface;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JSeparator;
import javax.swing.KeyStroke;


public class NorthPanel extends JMenuBar implements ActionListener
{

    public NorthPanel()
    {
        //Set parameters of north panel
        setSize(100,768);
        setLayout(new GridLayout(1,1));

        //Add a menubar to the north panel
        add(getMenuBar());
    }

    /*
     * Method to create and build the menubar using methods that build each
     * JMenu.
     */
    private JMenuBar getMenuBar()
    {
        JMenuBar topMenu = new JMenuBar();

        topMenu.add(getFileMenu());
        topMenu.add(getTheHelpMenu());

        return topMenu;
    }

    /*
     * Populate the file menu with various menu options each with their own
     * hotkey.
     */
    private JMenu getFileMenu()
    {
            JMenu fileMenu = new JMenu("File");

            JMenuItem newGame = new JMenuItem("New Game");
            newGame.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.ALT_MASK));
            newGame.addActionListener(this);
            newGame.setActionCommand("new");

            JMenuItem saveGame = new JMenuItem("Save Game");
            saveGame.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.ALT_MASK));
            saveGame.addActionListener(this);
            saveGame.setActionCommand("save");

            JMenuItem loadGame = new JMenuItem("Load Game");
            loadGame.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L, ActionEvent.ALT_MASK));
            loadGame.addActionListener(this);
            loadGame.setActionCommand("load");

            JMenuItem quitProgram = new JMenuItem("Quit");
            quitProgram.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.ALT_MASK));
            quitProgram.addActionListener(this);
            quitProgram.setActionCommand("quit");

            fileMenu.add(newGame);
            fileMenu.add(saveGame);
            fileMenu.add(loadGame);
            fileMenu.add(new JSeparator());
            fileMenu.add(quitProgram);

            return fileMenu;
    }

    /*
     * Populate the help menu with various menu options each with their own
     * hotkey.
     */
    private JMenu getTheHelpMenu()
    {
            JMenu helpMenu = new JMenu("Help");

            JMenuItem help = new JMenuItem("Help");
            help.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_H, ActionEvent.ALT_MASK));
            help.addActionListener(this);
            help.setActionCommand("help");

            JMenuItem about = new JMenuItem("About");
            about.addActionListener(this);
            about.setActionCommand("about");

            JMenuItem hotkeys = new JMenuItem("Hotkeys");
            hotkeys.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_QUOTE, ActionEvent.ALT_MASK));
            hotkeys.addActionListener(this);
            hotkeys.setActionCommand("hotkeys");

            helpMenu.add(help);
            helpMenu.add(hotkeys);
            helpMenu.add(new JSeparator());
            helpMenu.add(about);

            return helpMenu;
    }

    public void actionPerformed(ActionEvent e) {
        String actionCommand = e.getActionCommand();

        if(actionCommand.equals("quit"))
        {
            System.exit(0);
        }
    }

            public void keyTyped(KeyEvent e) {

    }

}
      
